﻿using System;

namespace ExcelConfig.StoreAPI
{
    using ExcelConfig.Config;
    using SanlieHash.Fast;
    public class ConfigStoreHelper
    {
        
        public static void EnterConfigStoreAPIConfig()
        {
            ExcelConfigHelper.Enter("配置中心地址");

            var e = ExcelConfigSetting.PasswordEncrypt;
            ExcelConfigSetting.PasswordEncrypt = encrypt_password_S1;
            ExcelConfigHelper.EnterPassword("验证密码");

            if (!AppConfig.Text("验证密码").Contains("S1_")) ExcelConfigHelper.EnterPassword("验证密码", true);
            ExcelConfigSetting.PasswordEncrypt = e;
        }
        internal static void encrypt_password_S1(ref string pwd)
        {
            var guid = FastEncode.EncodeHex(Guid.NewGuid().ToByteArray());
            var zuc = FastGuoMi.GetZUC(guid, pwd);
            zuc.Jump(pwd.Length);
            var p1 = zuc.NextHex();
            var p2 = FastGuoMi.GetSM3($"S1_{p1}-{pwd}-{guid}");
            pwd = $"S1_{guid}-{p1}-{p2}";
        }
    }
}
